<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">-->
<title>机构编辑</title>
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, unit-scalable=no">

<jsp:include page="../common/import.jsp"></jsp:include>
</head>
<body>
	<!-- <div class="iframe-cot pt0" id="smIframe"> -->
    <div class="right-form mt0">
       <form class="add-form" id="editForm" method="post" action="#" onsubmit="return false;">
          <input id="s_unitId" type="hidden" value="${unit.unitId}">
		<ul class="w100 layer-form">
               <li>
                   <label class="ser-label"><em style="color:red;">*</em>机构名：</label>
                   <div class="form-content">
                       <input id="unitName" name="unitName" class="inputText" value="${unit.unitName}" type="text">
                   	   <div class="form-tips text-red" ></div>
                   </div>
               </li>
               <li>
                   <label class="ser-label">编码：</label>
                   <div class="form-content">
                      <input id="s_unitNO" name="unitNO" class="inputText_sm" value="${unit.unitNO}" type="text">
                      <div class="form-tips text-red" ></div>
                   </div>
               </li>
               <li>
                   <label class="ser-label"><em class="text-red mr5">*</em>上级机构：</label>
                   <div class="form-content">
                   	<input id="s_parentId" name="parentId" class="inputText" value="${unit.parentId}"  type="hidden"/>
                   	<input id="s_parentUnitName" name="parentUnitName"  value="${parentUnitName}" type="text" readonly="readonly"/>
                    <div class="form-tips text-red" ></div>
                   </div>
               </li>             
               <li >
                   <label class="ser-label">类型：</label>
                   <div class="form-content clearfix">
                   	<input  name="s_unitType"  value="1" type="radio" <c:if test="${'0' ne unit.unitType }">checked</c:if> >部门
                   	<input  name="s_unitType"  value="0" type="radio" <c:if test="${ '0' eq unit.unitType }">checked</c:if> >单位
                   </div>
               </li>
               <li >
                   <label class="ser-label">状态：</label>
                   <div class="form-content clearfix">
                   	<input  name="s_status"  value="1" type="radio" <c:if test="${ '0' ne unit.status }">checked</c:if> >启用
                   	<input  name="s_status"  value="0" type="radio" <c:if test="${'0' eq unit.status }">checked</c:if> >停用
                   </div>
               </li>
                  
               <li class="w-per">
                   <label class="ser-label">&nbsp;</label>
                   <div class="form-content clearfix">
                       <button class="btn btn-orange" id="savebtn" onclick="save()" ><i class="fa fa-save mr5"></i>保存</button>
                       <button id="cancelBtn" class="btn btn-default" onclick="closeLayerOpen()"><i class="fa fa-reply mr5"></i>返回</button>
                   </div>
               </li>
            </ul>
    	</form>
    </div>
  <!-- </div>  -->
<div id="treediv" style='top:75px;left:50px;overflow:scroll;display:none; position:absolute;width:300px;height:200px;background-color:#eeffdd; border:1px solid #BEC0BF;padding:5px;font-size:12px;'>
	<a onclick="hidetreediv();" href="#" class="link-red mr5" style="cursor:pointer;color:red;text-align:right;"><i class="fa fa-close"></i>取消</a>
	<ul id="tree" class="ztree"></ul>
</div>
</body>
<script type="text/javascript">
function closeLayerOpen(){
	parent.layer.close(parent.layer.getFrameIndex(window.name));
}

$("#editForm").validate({
	onkeyup : false,
	onsubmit: false,
	onfocusout:  function(element){
	      $(element).valid() ;
				 }, 
	rules : {
		unitName : {
			required : true,
			maxlength:50,
			isContainsSpecialChar: true 
		},
		unitNO : {
			maxlength:100,
		},
		parentUnitName : {
			required:true
		}

	},
	messages : {
		unitName : {
			required : "请完善必填信息",
			maxlength : "请输入正确的机构名称",
			isContainsSpecialChar : "请输入正确的机构名称"
		},
		description : {
			maxlength : "请输入正确的编码"
		},
		parentUnitName : {
			required:"请完善必填信息"
		}
	},
	errorPlacement: function(error, element) {
		 if(error){    //error存在的时候
			 $(element).next().html(error); //showMsg为你自定义的信息显示区域的id。
			
		 }                            //这里的element是录入数据的对象  
		 $(element).addClass('input-danger');
		 
	 },
	 success:function(label){
		 $(label).parent().prev().removeClass('input-danger');
		
	 }
});

function save(){
	//校验
	if(!$("#unitName").valid() ||!$("#s_unitNO").valid() || !$("#s_parentUnitName").valid() ){
		return false;
	}		
	var unitName=$("#unitName").val();
	var unitNO=$("#s_unitNO").val();
	var parentId=$("#s_parentId").val();
	var unitId=$("#s_unitId").val();
	var status=$("input:radio[name='s_status']:checked").val();
	var unitType=$("input:radio[name='s_unitType']:checked").val();
	
	
	var data={
			unitId:unitId,
			unitName:unitName,
			parentId:parentId,
			unitNO:unitNO,
			status:status,
			unitType:unitType
			};
	$("#savebtn").attr('disabled','disabled');
 	$.post("${ctx}/unit/save",data,function(result){
		if(result.code=="success"){
			 layer.msg('操作成功', {
  	            icon: 1
  	        });
			 window.parent.changePage('${ctx}/unit/list','#unitQueryForm'
					 ,'${currentPage}','${pageSize}',0);
			setInterval("parent.layer.close(parent.layer.getFrameIndex(window.name))",2000);
			// changePage('${queryList }','',1,15,0);
		}else{
			layer.msg('操作失败', {
  	            icon: 2
  	        });
			$("#savebtn").removeAttr('disabled');
		}
	},"json"); 
	}


$(document).ready(function() {
	$("#s_parentUnitName").focus(function() {
		var divObj = $("#treediv");
    	var txtObj = $("#s_parentUnitName");
    	showDiv(divObj,txtObj,punitsetting,"${ctx}/user/getUnit");
    	
	});
});


</script>
</html>